<template>
  <a-card :bordered="false">

    <!-- 操作按钮区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item prop="name" label="流程名称">
              <a-input v-model="queryParam.name" allowClear placeholder="请输入流程名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item prop="processKey" label="流程KEY">
              <a-input v-model="queryParam.processKey" allowClear placeholder="请输入流程KEY" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item prop="formKey" label="表单KEY">
              <a-input v-model="queryParam.formKey" allowClear placeholder="请输入表单KEY" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :xl="7" :lg="7" :md="8" :sm="16">
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-button type="primary" @click="searchQuery" icon="search" style="margin-right: 8px">查询</a-button>
                <a-button type="primary" @click="searchReset" icon="reload" style="margin-right: 8px">重置</a-button>
              </span>
          </a-col>
          <a-col :xl="2" :lg="7" :md="8" :sm="8" style="text-align: right">
            <a-button @click="handleAdd" type="primary" icon="plus" style="background-color: #5FB878;border-color: #5FB878">新增</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>

        <template slot="status" slot-scope="text,record">
          <span v-if="record.status=='1'" style="color: #7ac23c">启用</span>
          <span v-if="record.status=='2'" style="color: #ff0000">未启用</span>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a style="color: red">删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <apply-form-modal ref="modalForm" @ok="modalFormOk"></apply-form-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ApplyFormModal from './modules/ApplyFormModal'

  export default {
    name: 'ApplyFormList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      ApplyFormModal
    },
    data () {
      return {
        description: 'apply_form管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function (t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            title: '名称',
            align: 'center',
            dataIndex: 'name'
          },
          {
            title: '图标',
            align: 'center',
            dataIndex: 'icon'
          },
          {
            title: '绑定流程KEY',
            align: 'center',
            dataIndex: 'processKey'
          },
          {
            title: '绑定表单KEY',
            align: 'center',
            dataIndex: 'formKey'
          },
          {
            title: '启用状态',
            align: 'center',
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            fixed: 'right',
            width: 147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/applyform/list',
          delete: '/applyform/delete',
          deleteBatch: '/applyform/deleteBatch',
          exportXlsUrl: '/applyform/exportXls',
          importExcelUrl: 'applyform/importExcel'

        },
        dictOptions: {},
        superFieldList: [],
        queryParam: {
           processKey: '',
           formKey: '',
           name: ''
        }
      }
    },
    created() {
    this.getSuperFieldList()
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },
    methods: {
      initDictConfig() {
      },
      getSuperFieldList() {
        let fieldList = []
        fieldList.push({ type: 'string', value: 'name', text: '名称' })
        fieldList.push({ type: 'string', value: 'icon', text: '图标' })
        fieldList.push({ type: 'string', value: 'processKey', text: '绑定流程key' })
        fieldList.push({ type: 'string', value: 'formKey', text: '绑定表单key' })
        fieldList.push({ type: 'string', value: 'status', text: '启用状态' })
        fieldList.push({ type: 'string', value: 'rangeuse', text: '选择使用范围' })
        fieldList.push({ type: 'int', value: 'delFlag', text: '删除状态(0-正常,1-已删除)' })
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
